require("../../utils/util.js");

var e = require("../../requests/request.js");

Component({
    properties: {},
    data: {
        modelshow: !1,
        caryears: {},
        currenttab: 0,
        enginetypes: {},
        currentcars: {}
    },
    methods: {
        showCar: function(e) {
            var r = this;
            r.loadCars(e.serialid), r.setData({
                modelshow: !r.data.modelshow
            });
        },
        hideCar: function() {
            this.setData({
                modelshow: !this.data.modelshow
            });
        },
        loadCars: function(r) {
            var a = this, t = this;
            e.getCarList(r, function(e) {
                console.log(e);
                for (var r = [], s = [], n = 0; n < e.length; n++) 2 == e[n].SaleStatus ? e[n].Car_YearType = "未上市" : e[n].Car_YearType = e[n].Car_YearType + "款", 
                r.contains(e[n].Car_YearType) || r.push(e[n].Car_YearType), e[n].Mali = Math.round(1e3 * e[n].Power / 735);
                console.log(r.sort().reverse());
                var i = !1, s = [];
                r.indexOf("未上市") > -1 && (i = !0, r.splice(r.indexOf("未上市"), 1), (s = r.sort().reverse()).push("未上市")), 
                t.setData({
                    carlist: e,
                    caryears: i ? s : r.sort().reverse()
                }), a.getCurrentCars();
            }, null, function() {
                t.setData({
                    loading: !1
                });
            });
        },
        getCurrentCars: function() {
            for (var e = this.data.caryears[this.data.currenttab], r = [], a = [], t = [], s = 0; s < this.data.carlist.length; s++) if (this.data.carlist[s].Car_YearType == e) {
                var n = this.data.carlist[s], i = "";
                n.Mali && n.Mali > 0 && (i += n.Mali + "马力"), n.UnderPan_ForwardGearNum && n.UnderPan_ForwardGearNum > 0 && (i += n.UnderPan_ForwardGearNum + "档"), 
                n.UnderPan_TransmissionType && "" != n.UnderPan_TransmissionType && (i += n.UnderPan_TransmissionType), 
                n.maliDesc = i, r.push(n);
                var o = n.Engine_ExhaustForFloat + "L/" + n.Power + "kW " + n.Engine_AddPressType, u = "";
                n.Engine_ExhaustForFloat && "" != n.Engine_ExhaustForFloat && n.Engine_ExhaustForFloat > 0 && (u += n.Engine_ExhaustForFloat + "L"), 
                n.Power > 0 && (u += "" != u ? "/" + n.Power + "kW " : n.Power + "kW "), "" != n.Engine_AddPressType && "无" != n.Engine_AddPressType && (u += n.Engine_AddPressType);
                var d = {
                    Key: o,
                    Value: u.replace("undefined", ""),
                    Exhause: parseFloat(n.Engine_ExhaustForFloat),
                    Power: parseInt(n.Power)
                };
                t.contains(d.Key) || (t.push(d.Key), a.push(d));
            }
            this.setData({
                currentcars: r.sort(function(e, r) {
                    return e.CarReferPrice.replace("万", "") - r.CarReferPrice.replace("万", "");
                }),
                enginetypes: a.sort(function(e, r) {
                    return e.Exhause == r.Exhause ? e.Power - r.Power : e.Exhause - r.Exhause;
                })
            });
        },
        bindTab: function(e) {
            var r = e.currentTarget.dataset.index;
            this.setData({
                currenttab: r
            }), this.getCurrentCars();
        },
        bindJump: function(e) {
            var r = {};
            r.carid = e.currentTarget.dataset.carid, r.carname = e.currentTarget.dataset.carname, 
            r.showname = e.currentTarget.dataset.showname, r.img = e.currentTarget.dataset.img;
            var a = this;
            this.triggerEvent("callback", r, a);
        }
    }
});